<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit">
  	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<title>${SYSTEM_NAME}</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css?v=${FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css?v=${FILE_VERSION}" media="all">
</head>
<body>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-body" style="padding: 15px;">
		<form class="layui-form" method="post" id="basicform" >
			<input id="id" name="id" value="${generatorTable.id }" type="hidden">
			
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label layui-form-required">数据库表名</label>
				<div class="layui-input-block">
					${generatorTable.tableName}
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label layui-form-required">生成类名称</label>
				<div class="layui-input-block">
					<input name="className" placeholder="请输入生成类名称"
						   class="layui-input" lay-verify="required" value="${generatorTable.className }" maxlength="100">
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label layui-form-required">生成类注释</label>
				<div class="layui-input-block">
					<input name="tableComment" placeholder="请输入生成类注释"
						   class="layui-input" lay-verify="required" value="${generatorTable.tableComment }" maxlength="100">
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label layui-form-required">模块名称</label>
				<div class="layui-input-block">
					<input name="moudleName" placeholder="请输入模块名称"
						   class="layui-input" lay-verify="required" value="${generatorTable.moudleName }" maxlength="100">
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label layui-form-required">文件夹名</label>
				<div class="layui-input-block">
					<input name="fileDirName" placeholder="请输入文件夹名"
						   class="layui-input" lay-verify="required" value="${generatorTable.fileDirName }" maxlength="100">
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">权限</label>
				<div class="layui-input-block">
					<input name="shiro" placeholder="请输入权限"
						   class="layui-input" value="${generatorTable.shiro }" maxlength="100">
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label layui-form-required">model继承类</label>
				<div class="layui-input-inline">
					<select  lay-verify="required" name="modelInherits">
						<c:forEach items="${modelInheritsMap}" var="t">
							<option value="${t.key }" <c:if test="${t.key eq generatorTable.modelInherits}">selected="selected"</c:if>>${t.value }</option>
						</c:forEach>
					</select>
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label layui-form-required">页面模板</label>
				<div class="layui-input-inline">
					<select  lay-verify="required" name="pageModel">
						<c:forEach items="${pageModelMap}" var="t">
							<option value="${t.key }" <c:if test="${t.key eq generatorTable.pageModel}">selected="selected"</c:if>>${t.value }</option>
						</c:forEach>
					</select>
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">父级菜单<font style="color:red">(不填写代表不生成)</font></label>
				<div class="layui-input-inline">
					<input type="hidden" id="parentId" name="menuParentId"
						   value="${generatorTable.menuParentId}" >
					<input type="text" id="parentName" class="layui-input"
						   readonly="readonly" value="${generatorTable.menuParentId}"
						   placeholder="点击选择父类菜单" onclick="selectMenu()">
				</div>
				<div class="layui-input-inline">
					<button type="button" class="layui-btn" onclick="selectMenu()">点击选择</button>
					<button type="button" class="layui-btn layui-btn-primary" onclick="clearMenu()">清空菜单</button>
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label layui-form-required">需要生成的文件</label>
				<div class="layui-input-inline" id="needFiles">
					<c:forEach items="${needFileMap}" var="t">
						<input type="checkbox" name="needFileInput" title="${t.value}" value="${t.key}"
							<c:if test="${fn:contains(generatorTable.needFile, t.key)}">
								checked
							</c:if>/>
					</c:forEach>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-primary layui-border-blue" lay-submit="" lay-filter="sub">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary layui-border-blue">重置</button>
					<button type="button" class="layui-btn layui-btn-primary layui-border-red" onclick="closed()">关闭</button>
				</div>
			</div>
		</form>
	</div>
	</div>
</div>
	<script src="${pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${FILE_VERSION}"></script>
	<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${FILE_VERSION}"></script>
	<script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${FILE_VERSION}"></script>
	<script src="${pageContext.request.contextPath}/static/js/common/coreInput-2.0.0.js?v=${FILE_VERSION}"></script>

	<script>
		layui.use(['form', 'element','layer'], function() {
			var form = layui.form;

			form.on('submit(sub)', function(data){
				var needFile = "";
				$('input[name="needFileInput"]:checked').each(function(){
					needFile += $(this).val() + ",";
				});
				needFile = needFile.substr(0, needFile.length - 1);
				data.field["needFile"] = needFile;

				$ajax({
					url: "/generator/table/edit/save",
					data :  data.field,
			        succCallback: function (json) {
			        	if(json.code == 0){
			        		parent.reload();
		            		parent.layer.closeAll();
		            		parent.layer.msg(json.msg);
			        	}
			        }
				});
				return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		});

		function selectMenu(){
			var url  = getContextPath() +  "/sys/menu/setMenu?queryTop=false";
			layer.open({
				title : "选择菜单",
				type: 2,
				area: ['500px', '90%'],
				anim: 2,
				content: [url, 'yes']
			});
		}

		function setMenuValue(id,name){
			$("#parentId").val(id);
			$("#parentName").val(name);
			layer.closeAll();
		}

		function clearMenu(){
			$("#parentId").val("");
			$("#parentName").val("");
		}
	</script>
</body>
</html>